// 接雨水
/**
 * @param {number[]} height
 * @return {number}
 */
 var trap = function(height) {
    let n = height.length;
    let leftm = 0, rightm = 0;
    let l = 0, r = n-1;
    let ans = 0;
    while(l<r) {
       leftm = Math.max(leftm,height[l]);
       rightm = Math.max(rightm,height[r]);
       if(height[l] < height[r]) {
           ans += leftm-height[l]
          ++l;
       }
       else {
           ans += rightm-height[r]
           --r;
       }
    }
    return ans;
    };